import 'dart:async';

import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';

part 'cart_event.dart';
part 'cart_state.dart';

class CartBloc extends Bloc<CartEvent, CartState> {
  String listCartStr;
  CartBloc() : super(CartInitialState(''));
  // '[{"commodityId":3,"commodityName":"Apple/苹果 10.9 英寸 iPad Air","commodityDescribe":"","commodityImg":"1618907346792.png","commodityImgMedium":"/category/img/3/2/show/1618907346792.png","commodityImgBig":"/category/img/3/2/show/1618907346793.png","commodityOriginalPrice":"4999","commodityDiscountPrice":"4799","commodityCreateTime":"2021-04-20 16:29:07.0","categoryId":3,"categorySubId":2,"commodityImg1":"/category/img/3/2/carousel/1618907346794.png","commodityImg2":"/category/img/3/2/carousel/1618907346796.png","commodityImg3":"/category/img/3/2/carousel/1618907346797.png","commodityImg4":"/category/img/3/2/carousel/1618907346798.png","commodityImgDetails1":"","commodityImgDetails2":"","commodityImgDetails3":"","commodityImgDetails4":""},{"commodityId":4,"commodityName":"小米平板4plus","commodityDescribe":null,"commodityImg":"mipad.jpg","commodityImgMedium":"/goods/3/2/mipad.jpg","commodityImgBig":"/goods/3/2/mipad.jpg","commodityOriginalPrice":"1999","commodityDiscountPrice":"1799","commodityCreateTime":"2021-04-20 16:43:03.0","categoryId":3,"categorySubId":2,"commodityImg1":"/goods/3/2/mipad.jpg","commodityImg2":null,"commodityImg3":null,"commodityImg4":null,"commodityImgDetails1":"/goods/3/2/mipad.jpg","commodityImgDetails2":null,"commodityImgDetails3":null,"commodityImgDetails4":null},{"commodityId":5,"commodityName":"Samsung/三星 Galaxy Tab A7 2020新款学生学习 官方正品旗舰店三星平板电脑","commodityDescribe":"","commodityImg":"sx.jpg","commodityImgMedium":"/goods/3/2/sx.jpg","commodityImgBig":"/goods/3/2/sx.jpg","commodityOriginalPrice":"1699","commodityDiscountPrice":"1499","commodityCreateTime":"2021-04-20 16:49:46.0","categoryId":3,"categorySubId":2,"commodityImg1":"/goods/3/2/sx.jpg","commodityImg2":"/goods/3/2/sx.jpg","commodityImg3":"/goods/3/2/sx.jpg","commodityImg4":"/goods/3/2/sx.jpg","commodityImgDetails1":"/goods/3/2/sx.jpg","commodityImgDetails2":"/goods/3/2/sx.jpg","commodityImgDetails3":"/goods/3/2/sx.jpg","commodityImgDetails4":"/goods/3/2/sx.jpg"}]'

  @override
  Stream<CartState> mapEventToState(
    CartEvent event,
  ) async* {
    if (event is SetCartEvent) {
      yield* _mapSetEvent(event);
    }
  }

  Stream<CartState> _mapSetEvent(SetCartEvent event) async* {
    this.listCartStr = event.listCartStr;
    yield CartChangeState(this.listCartStr);
  }
}
